Skip to content

Conversation

@rolf-yoast
Copy link

@rolf-yoast rolf-yoast commented Apr 19, 2024

Fixes #239

@rolf-yoast rolf-yoast requested a review from a team as a code owner April 19, 2024 06:23
@rolf-yoast rolf-yoast changed the title Introduce Column interface for the right alignment names Add alignment functionality to tables Apr 19, 2024
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @rolf-yoast !

Could you add some tests for this PR?

Also, it would be nice to address your TODO comment.

@swissspidy swissspidy requested a review from Copilot November 2, 2025 14:07
@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 76.19048% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/cli/Table.php 58.33% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for column alignment in CLI tables. The implementation allows users to specify left, right, or center alignment for table columns using alignment constants defined in a new Column interface.

Key changes:

  • Introduced a new Column interface with alignment constants mapped to PHP's STR_PAD_* constants
  • Added alignment tracking and configuration throughout the table rendering pipeline
  • Modified the Ascii renderer to apply column-specific alignments when padding cell content

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
lib/cli/table/Column.php Defines new interface with alignment constants (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER)
lib/cli/table/Renderer.php Adds $_alignments property and setAlignments() method to base renderer class
lib/cli/table/Ascii.php Implements alignment logic by storing headers and applying column-specific alignment in padColumn()
lib/cli/Table.php Adds alignment parameter to constructor and propagates alignments to renderer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swissspidy swissspidy requested a review from Copilot November 2, 2025 16:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +216 to +227
public function setAlignments(array $alignments) {
$validAlignments = array(Column::ALIGN_LEFT, Column::ALIGN_RIGHT, Column::ALIGN_CENTER);
foreach ($alignments as $column => $alignment) {
if (!in_array($alignment, $validAlignments, true)) {
throw new \InvalidArgumentException("Invalid alignment value '$alignment' for column '$column'.");
}
if (!in_array($column, $this->_headers, true)) {
throw new \InvalidArgumentException("Column '$column' does not exist in table headers.");
}
}
$this->_alignments = $alignments;
}
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation on line 222 checks if headers exist before alignments are set, but setAlignments() can be called in the constructor at line 68 before setHeaders() is called at line 64 when the constructor is invoked with an empty headers array and a non-empty alignments array. This will cause the validation to always fail in that case because $this->_headers will be empty. Consider either validating alignments lazily when they're used, or reordering the constructor calls, or skipping validation when headers are empty.

Copilot uses AI. Check for mistakes.
Comment on lines +135 to +137
if ($this->_headers === null) {
$this->_headers = array_values($row);
}
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header tracking logic assumes the first row rendered is always the headers, but this may not be reliable if the renderer is reused or if rows are rendered in an unexpected order. Consider passing headers explicitly to the renderer via a dedicated method (e.g., setHeaders()) rather than inferring them from the first row call to row().

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is it possible to enhance table format with right-align numeric values easily?

3 participants